﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SpotIt
{
    /// <summary>
    /// Interaction logic for SpotIt_Play_Single.xaml
    /// </summary>
    public partial class SpotIt_Play_Single : Window
    {
        AudioFiles theAudioFiles = AudioFiles.Instance;
        Settings settings = Settings.Instance;
        public delegate void voidMethod();
        public event voidMethod startMusic;
        public SpotIt_Play_Single()
        {
            InitializeComponent();
            this.scoreLabel.Content = "0";
        }

        /**this function increments the score to the current amount
         * 
         * @param addScore this pertains to the ammount that you need to increment to the curent score
         * */
        public void incrementScore(int addScore)
        {
            int currentScore = Convert.ToInt32(scoreLabel.Content);
            currentScore += addScore;
            scoreLabel.Content = currentScore;
        }

        private void mainMenuButton_Click(object sender, RoutedEventArgs e)
        {
            theAudioFiles.theFiles[1].Stop();
            this.Close();
            startMusic();
        }

        private void MusicOnOffToggle_Click(object sender, RoutedEventArgs e)
        {
            theAudioFiles.theFiles[3].Play();
            if (theAudioFiles.theFiles[1].IsPlaying)
            {
                theAudioFiles.theFiles[1].Stop();
                main_noImage.Visibility = Visibility.Visible;
                main_musicImage.Opacity = .45;
                settings.musicOn = false;
            }
            else
            {
                if (main_noImage.Visibility == Visibility.Visible)
                {
                    settings.musicOn = true;
                    main_noImage.Visibility = Visibility.Hidden;
                    theAudioFiles.theFiles[1].Play();
                    main_musicImage.Opacity = 1;
                }
                else
                {
                    settings.musicOn = false;
                    main_noImage.Visibility = Visibility.Visible;
                    main_musicImage.Opacity = .45;
                }
            }
            settings.saveSettings();
        }

        private void spotItcard2_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (theAudioFiles.theFiles[1].IsPlaying)
                settings.musicOn = true;
            //else
                //settings.musicOn = false;
        }

        private void Window_Initialized(object sender, EventArgs e)
        {
            if (settings.musicOn)
                theAudioFiles.theFiles[1].Play();
            else
            {
                main_noImage.Visibility = Visibility.Visible;
                main_musicImage.Opacity = .45;
            }

        }
    }
}
